import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { rules } from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
//列表数据
export const columns: BasicColumn[] = [
  {
    title: '小说ID',
    align: 'center',
    dataIndex: 'id',
    width: 200,
  },
  {
    title: '作品方向',
    align: 'center',
    dataIndex: 'workDirectionStr',
  },
  {
    title: '分类名',
    align: 'center',
    dataIndex: 'catName',
  },
  {
    title: '小说名',
    align: 'center',
    dataIndex: 'bookName',
    ellipsis: false,
  },
  {
    title: '作者名',
    align: 'center',
    dataIndex: 'authorName',
  },
  {
    title: '书籍状态',
    align: 'center',
    dataIndex: 'bookStatus',
    customRender: ({ text }) => {
      return text ? '已完结' : '连载中';
    },
  },
  {
    title: '点击量',
    align: 'center',
    dataIndex: 'visitCount',
  },
  {
    title: '总字数',
    align: 'center',
    dataIndex: 'wordCount',
  },
  {
    title: '评论数',
    align: 'center',
    dataIndex: 'commentCount',
  },
  {
    title: '昨日订阅数',
    align: 'center',
    dataIndex: 'yesterdayBuy',
  },
  {
    title: '最新章节编号',
    align: 'center',
    dataIndex: 'indexNum',
  },
  {
    title: '最新章节',
    align: 'center',
    dataIndex: 'lastIndexName',
  },
  {
    title: '最新章节更新时间',
    align: 'center',
    dataIndex: 'lastIndexUpdateTime',
  },
  {
    title: '是否收费',
    align: 'center',
    dataIndex: 'isVip',
    customRender: ({ text }) => {
      return text ? '收费' : '免费';
    },
  },
  {
    title: '入库时间',
    align: 'center',
    dataIndex: 'createTime',
  },
  {
    title: '是否自动采集',
    align: 'center',
    dataIndex: 'isAutoCollection',
    customRender: ({ text }) => {
      return text ? '是' : '否';
    },
  },
  {
    title: '采集状态',
    align: 'center',
    dataIndex: 'collectionStatus',
    customRender: ({ text, record }) => {
      let str = '';
      if (record.isAutoCollection) {
        if (text === 0) {
          str = '失败';
        } else if (text === 1) {
          str = '成功';
        } else if (text === 2) {
          str = '进行中';
        }
      }
      return str;
    },
  },
  {
    title: '采集器',
    align: 'center',
    dataIndex: 'collector_dictText',
  },
  {
    title: '采集地址',
    align: 'center',
    dataIndex: 'collectionUrl',
  },
  {
    title: '是否签约',
    align: 'center',
    dataIndex: 'isContract',
    customRender: ({ text }) => {
      return text ? '是' : '否';
    },
  },
];
columns.forEach((item) => {
  item.resizable = true;
});
//查询数据
export const searchFormSchema: FormSchema[] = [
  {
    label: '小说ID',
    field: 'bookId',
    component: 'Input',
    colProps: { span: 6 },
  },
];

//表单数据
export const formSchema: FormSchema[] = [
  {
    label: '小说ID',
    field: 'bookId',
    component: 'InputNumber',
    dynamicRules: ({ model, schema }) => {
      return [{ required: true, message: '请输入小说ID!' }];
    },
  },
  {
    label: '目录号',
    field: 'indexNum',
    component: 'InputNumber',
    dynamicRules: ({ model, schema }) => {
      return [{ required: true, message: '请输入目录号!' }];
    },
  },
  {
    label: '目录名',
    field: 'indexName',
    component: 'Input',
  },
  {
    label: '字数',
    field: 'wordCount',
    component: 'InputNumber',
  },
  {
    label: '是否收费',
    field: 'isVip',
    component: 'JSwitch',
    componentProps: {},
  },
  {
    label: '章节费用（屋币）',
    field: 'bookPrice',
    component: 'InputNumber',
  },
  {
    label: '存储方式',
    field: 'storageType',
    component: 'Input',
    dynamicRules: ({ model, schema }) => {
      return [{ required: true, message: '请输入存储方式!' }];
    },
  },
  // TODO 主键隐藏字段，目前写死为ID
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false,
  },
];
